<%@page import="com.fs.base.param.SysConstant"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="/WEB-INF/jsp/include/easyui.jsp" %>
<%@ include file="../../include/pGrid.jsp" %>
<script src="/plug-in/jquery-easyui-1.5.1/plugins/jquery.choosebox.js"></script>
<%@ include file="/WEB-INF/jsp/include/easyui-layui-upload.jsp" %>
<script type="text/javascript" src="${path}/plug-in/jquery-easyui-1.5.1/plugins/datagrid-cellediting.js"></script>
<%@ include file="../../include/pForm.jsp" %>
<title>入库记录编辑</title>
<script>
$(function(){
	fn.resetForm();
	var _data = fn.getDialogData();
	var userDialog = null;
	$("#dataGrid").datagrid({
		idField: "id",
		//fit: true,
		rownumbers: true,
		pagination: true,
		singleSelect: true, 
		url : '/console/com.fs.jzzn.pojo.StorageItem/list',
		queryParams: {
			billNo:_data.billNo,
			billNo_searchType: "eq"
		},
		columns : [[ 
		    	{field:  'stockId',title:'库存主键',hidden:true }
				,{field:  'stockCount',title:'库存数量',hidden:true }
				
				,{field: 'mNo', title: '物料编码', width: 120}
			    , {field: 'mName', title: '物料名称', width: 150,editor:{
		    		type:'text',
		    		required:true
		    	}} 
		    	,{field: 'mType', title: '物料规格', width: 100,editor:{
		    		type:'text',
		    		required:true
		    	}}
		    	,{field: 'mCount', title: '入库数量', width: 100,editor:{type:'numberbox',options:{precision:0,required:true,min:1 }}}
		    	,{field: 'mUnit', title: '物料单位', width: 80,editor:{
		    		type:'combobox',
					options:{
						method:'get',
						url:'/console/materiel/rewrite/combobox?valueField=mUnit&textField=mUnit',
						required:true
					}
		    	}}
		    	,{field : 'warehouseName',width : 80,	title : '仓库名称',editor:{
		    		type:'combobox',
					options:{
						method:'get',
						url:'/console/combobox?valueField=dicName&textField=dicName&modleName=dictionary&pCode=C3&pCode_searchType=eq',
						required:true
					}
		    	}}
		    	,{field: 'location', title: '库位', width: 100,editor:{
		    		type:'text',
		    		required:true
		    	}}
		    	,{field: 'opt', title: '操作', width: 80,formatter: function(value,row,index){
		    		return '<a href="#" onclick="deleteRow('+ index +')">删除</a>';
		    	}}
		]],
		toolbar: [{
			iconCls: 'icon-add', text: '添加', handler: function(){
				var $this =  $(this);
				$this.linkbutton('disable');
				setTimeout(function(){
					$this.linkbutton('enable');
				},500);
				
				userDialog = $("<div/>").dialog("openWin", { 
	     		    title: '入库物料选择',   
	     		    width:  750,
	     		    height: 500,   
	     		   href : '/console/materiel_choose_in/choosebox',
	     		    buttons : [
	     		        {
			            	   text : "确定", iconCls : "icon-ok", handler : function() {
			            		   var rows = userDialog.iframeWindow.choose() || [];
			            		   $.each(rows, function (i,item) {
			            			   item.mCount = 1;
			            			   $('#dataGrid').datagrid('appendRow',item);
			            		   });
			            		   userDialog.dialog('close');
			            	   }
	     		        },
							{
								text : "关闭", iconCls : "icon-no", handler : function() {
									userDialog.dialog('close');
								}
							}
	     		    ]
	     		});
	     		userDialog.dialog("center");
			}
		},'-'
		/*,{
			iconCls: 'icon-cut',text: '删除', handler: function(){
				var rows = $("#dataGrid").datagrid('getSelections') ;
				$.each(rows, function (i,item) {
     			   var index = $("#dataGrid").datagrid('getRowIndex',item);
     			   $("#dataGrid").datagrid('deleteRow',index) ;
     		   });
			}
		},'-'*/
		,{
			iconCls: 'icon-help',text: '帮助', handler: function(){
				$.messager.show({ title:'温馨提示', msg: '点击添加按钮，选择入库物料明细!',timeout:3000, showType:'slide' });
			}
		}]
	}).datagrid('enableCellEditing');
	
	/*表单提交前动作*/
	fn.onBeforeSubmitForm = function(){
		var rows = $("#dataGrid").datagrid('getRows') ;
		for(var index=0,len=rows.length;index<len;index++){
			$("#dataGrid").datagrid('endEdit',index);
		}
		$("input[name=storageItemJson]").val(JSON.stringify(rows));
		return true;
	}
});

function deleteRow(index){
	$("#dataGrid").datagrid('deleteRow',index) ;
}

/**
 * 自动根据项目选址所属项目部
 */
function departmentSelect(record){
	$('#department').combobox('setValue', record.department || '');
}
</script>
</head>
<body>
	<div class="easyui-panel" data-options="fit:true,border:false" style="padding:10px;">
		<form id="easyuiForm" method="post" action="/console/storage/rewrite/modify"   >
	 		<input type="hidden" name="className" value="com.fs.jzzn.pojo.Storage" />
	 		<input type="hidden" name="createrId" value="${SESSION_USER.user.id}" />
	 		<input type="hidden" name="id" value="" />
	 		<input type="hidden" name="storageItemJson" value="[]" />
	 		<input type="hidden" name="status" value="0" />
			
			<div style="margin-bottom:20px">
					<input  class="easyui-autoCode"  name="billNo" style="width:270px;" data-options="label:'入库编号:',required:true,prefix:'RK',timestamp:'yyMMddHHmmss' "/>
					<input class="easyui-choosebox easyui-validatebox" name="contractNo" style="width:540px;"   data-options="label:'订单编号:',boxWidth:900,boxHeight:400,boxTitle:'请选择订单编号',textField:'contractNo',valueField:'contractNo',modleName:'order' "/>
				</div>
				
				<div style="margin-bottom:20px">
					<input class="easyui-datebox" name="inDate"  style="width:270px;"  data-options="label:'入库日期:',required:false"  />
					<select class="easyui-combobox" id="pNo" name="pNo" style="width:540px;" data-options="label:'项目名称:',required:true,onSelect:departmentSelect" 
						url="/console/newProject/combobox?textField=pName&valueField=pNo&attributes=department" >
				   	 </select>
				 </div>
			
				<div style="margin-bottom:20px">
					<select class="easyui-combobox" name="sType" style="width:270px;" data-options="label:'入库类别:'" 
							url="/console/combobox?valueField=dicName&textField=dicName&modleName=dictionary&pCode=C2&pCode_searchType=eq&text=甲供" >
					 	</select>
					<select class="easyui-combobox" name="warehouseName" style="width:270px;" data-options="label:'仓库名称:'" 
							url="/console/combobox?valueField=dicName&textField=dicName&modleName=dictionary&pCode=C3&pCode_searchType=eq&text=东湖落雁岛" >
					 	</select>
					 	<select class="easyui-combobox" id="department" name="department" style="width:270px;" data-options="label:'关联项目部:',loadFilter:fn.departmentFilter" 
						url="/console/combobox?valueField=dicName&textField=dicName&modleName=dictionary&pCode=A5&pCode_searchType=eq" >
				    </select>
				 </div>
			
				<div style="margin-bottom:20px">
					 <input class="easyui-textbox" name="consignee"  style="width:270px;"  data-options="label:'收货人:',required:false"  />
					<input class="easyui-textbox" name="supplier"  style="width:270px;"  data-options="label:'供应商:',required:false"  />
					<input class="easyui-textbox" name="remark"  style="width:270px;"  data-options="label:'备注:',required:false,multiline:true,height:50,validType:'length[0,500]'"  />
				</div>
		
				<div style="margin-bottom:20px">
					<input class="easyui-layuiupload" name="attachment" style="width:925px;" data-options="label:'附件:',upload:{auto:false,height:120}" />
				</div>
			
				<div style="margin-bottom:20px;margin-left: 80px;">
					<table id="dataGrid" title="入库物料明细" style="height:270px;width:850px;"></table>
				</div>
		
	</div>
</body>
</html>